package com.system.controller;

import com.system.pojo.EmplAttendance;
import com.system.service.EmplAttendanceService;
import com.system.service.EmployeeSalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;

/**
 * Created by 陈文杰 on 2022/6/11 23:15
 */
@Controller
public class AttendanceController {

    @Autowired
    EmplAttendanceService emplAttendanceService;

    @Autowired
    EmployeeSalaryService employeeSalaryService;

    @RequestMapping("/toAttendance")
    public ModelAndView toAttendance() {
        ModelAndView modelAndView = new ModelAndView();
        List<EmplAttendance> emplAttendances = emplAttendanceService.queryEmplAttendanceAll();
        modelAndView.addObject("emplAttendances", emplAttendances);
        modelAndView.setViewName("attendance");
        return modelAndView;
    }

    @RequestMapping("/changeAttendanceDate")
    public String changeAttendanceDate(String empDate){//改变员工出勤日期及员工工资日期信息
        emplAttendanceService.updateEmplAttendanceDate(empDate);
        employeeSalaryService.updateEmployeeSalaryDate(empDate);
        return "redirect:toAttendance";
    }

    @RequestMapping("/changeAttendanceIsAtt")
    public String changeAttendanceIsAtt(int empIsAtt ,int empId){
        HashMap<String, Object> map = new HashMap<>();
        map.put("empIsAtt",empIsAtt);
        map.put("empId",empId);
        emplAttendanceService.updateEmplAttendanceByEmpId(map);
        return "redirect:toAttendance";
    }
}
